package com.macro.mall.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.BmsMuseumGroup;
import com.macro.mall.query.BmsMuseumGroupQuery;
import com.macro.mall.dto.BmsMuseumGroupParam;
import com.macro.mall.service.BmsMuseumGroupService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Controller
@Api(tags = "BmsMuseumGroupController")
@Tag(name = "BmsMuseumGroupController", description = "文博项目-预约时间维护")
@RequestMapping("/museumGroup")
public class BmsMuseumGroupController {

    @Autowired
    private BmsMuseumGroupService baseService;

    @ApiOperation("分页查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> findPage(@RequestBody BmsMuseumGroupQuery query) {
        try {
            List<BmsMuseumGroup> list = baseService.findPage(query);
            return CommonResult.success(CommonPage.restPage(list));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("获取列表")
    @RequestMapping(value = "/findList", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> findList(@RequestBody BmsMuseumGroupQuery query) {
        try {
            return CommonResult.success(baseService.findList(query));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("添加")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsMuseumGroupParam param) {
        try {
            return CommonResult.success(baseService.create(param));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsMuseumGroupParam param) {
        try {
            return CommonResult.success(baseService.update(param));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("根据id获取信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<?> getById(@PathVariable Long id) {
        try {
            BmsMuseumGroup entity = baseService.getById(id);
            return CommonResult.success(entity);
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestBody List<Long> ids) {
        try {
            return CommonResult.success(baseService.delete(ids));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

}
